package com.example.keli.ui.reward;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.example.keli.R;
import com.example.keli.base.BaseFragment;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * description $desc$
 * created by jerry on 2019/3/18.
 */
public class RewardFragment extends BaseFragment {

    private static final String TAG = "RewardFragment";
    @BindView(R.id.tabLayout)
    SlidingTabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    private MyPagerAdapter mAdapter;
    private ArrayList<Fragment> mFagments = new ArrayList<>();
    private String[] mTitles = {"奖品", "获奖名单"};

    @Override
    protected int layoutId() {
        return R.layout.fragment_reward;
    }

    @Override
    protected void bindData() {
        mFagments.add(RewardObjectFragment.newInstance());
        mFagments.add(RewardListFragment.newInstance());
        mAdapter = new MyPagerAdapter(getChildFragmentManager());

        viewPager.setAdapter(mAdapter);
        tabLayout.setViewPager(viewPager);
        viewPager.setCurrentItem(0);
    }

    @Override
    protected void bindListener() {

    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFagments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFagments.get(position);
        }
    }
}
